<?php
include('../../includes/classes/core.php');
 

$action	= $_REQUEST['act'];
$user_id= $_SESSION['USERID'];
$tab 	=	$_REQUEST['tab'];
$error	= '';
$data	= '';
$rout   = split(',' ,$_REQUEST[rout]);
if ($rout[4]=="false") {
    $rout[4]=" NOT ISNULL(districts.id)";
}
if ($rout[5]=="false") {
    $rout[5]=" ISNULL(districts.id)";
}

switch ($action) {
	case 'get_edit_page':
		$page 		= GetPage();
		$data		= array('page'	=> $page);

		break;
    case 'signature':
        $page 		= GetPage1();
        $data		= array('page'	=> $page);   
	   break;
	   
	case 'signature_save':	   
	    mysql_query("UPDATE `a_letter` 
                        SET `b_letter_signature`		=    $_REQUEST[signature_person], 
                        	`b_letter_signature_date`	=    NOW(),
                        	`b_letter_status`           =    1   
                     WHERE (`b_letter_overhead_id`='$_REQUEST[id]')");
	   	
	   	mysql_query("UPDATE `d_letter` 
                        SET `e_letter_signature`		=    $_REQUEST[signature_person], 
                        	`e_letter_signature_date`	=    NOW(),
                        	`e_letter_status`           =    1 
                     WHERE (`e_letter_overhead_id`='$_REQUEST[id]')");
	   	
                        	  break;	   
    case 'get_list':
	    $count = $_REQUEST['count'];
	    $hidden = $_REQUEST['hidden'];
	    switch ($tab){
	    	case 0:
//////----------------------მოსატანი-------------	    	 
//echo $rout[0];  
//return 0; 
	  	$rResult = mysql_query("
	    	    SELECT	CONCAT('a-',warehouse.id),
                		a_letter.`end_date`, 
                		CONCAT('ა  – ',a_letter.id)  as `letter`,
                		COUNT(*),
                		CONCAT(`client`.`name`,'(',`client_objects`.`name`, ')') AS `client`,
                		cities.`name`,
                		CONCAT(`client_objects`.address_name , ' ', `address_types`.`name` , ' ', `client_objects`.`address_number` ) AS `address`,
                		districts.`name`
                FROM	warehouse
                JOIN    a_letter ON warehouse.a_letter_id=a_letter.id
                JOIN    warehouse_detail ON warehouse_detail.warehouse_id =warehouse.id AND warehouse_detail.actived=1
                JOIN	client_objects ON `client_objects`.`id` = `a_letter`.`client_object_id`
                JOIN	client	ON `client`.`id` = `client_objects`.`client_id`
               LEFT JOIN	cities ON `cities`.`id` = `client_objects`.`region`
               LEFT JOIN	address_types ON `address_types`.`id` = `client_objects`.`address_type`
               LEFT JOIN	postal_codes	ON `postal_codes`.`id` = `client_objects`.postal_code_id
               LEFT JOIN	districts ON `districts`.`id` = `postal_codes`.`district_id` 
                WHERE	a_letter.receiver=0   AND 
                		a_letter.id>4500      AND
                		a_letter.actived=1    AND
                		ISNULL(a_letter.overhead_id) AND
                		(ISNULL(a_letter.overhead_id) AND ISNULL(a_letter.b_letter_overhead_id)) AND
                        (a_letter.status<2 AND warehouse.status<2) AND 
	    	            $rout[0] AND $rout[3] AND $rout[4] AND $rout[5] AND (districts.id in ($_REQUEST[districts]))
	    	    GROUP BY a_letter.id
	    	     
                UNION ALL
	    	    
                SELECT	CONCAT('d-',warehouse.id),
                        d_letter.`end_date`,
                        CONCAT('დ – ',d_letter.id)  as `letter`,
                        COUNT(*),
                        CONCAT(`client`.`name`,'(',`client_objects`.`name`, ')') AS `client`,
                        cities.`name`,
                        CONCAT(`client_objects`.address_name , ' ', `address_types`.`name` , ' ', `client_objects`.`address_number` ) AS `address`,
                        districts.`name`
                 FROM	warehouse
                 JOIN  d_letter ON warehouse.d_letter_id=d_letter.id
                 JOIN  warehouse_detail ON warehouse_detail.warehouse_id =warehouse.id AND warehouse_detail.actived=1
                 JOIN	`client_objects` ON `client_objects`.`id` = `d_letter`.`client_object_id`
                 JOIN	`client`	ON `client`.`id` = `client_objects`.`client_id`
                LEFT JOIN	`cities` ON `cities`.`id` = `client_objects`.`region`
                LEFT JOIN	`address_types` ON `address_types`.`id` = `client_objects`.`address_type`
                LEFT JOIN	`postal_codes`	ON `postal_codes`.`id` = `client_objects`.postal_code_id
                LEFT JOIN	`districts` ON `districts`.`id` = `postal_codes`.`district_id`
                 WHERE	d_letter.receiver=0   AND 
                        d_letter.id>450       AND
                        d_letter.actived=1    AND
                        (ISNULL(d_letter.overhead_id) AND ISNULL(d_letter.e_letter_overhead_id)) AND
                        (d_letter.status<2 AND warehouse.status<2) AND
	    	            $rout[0] AND $rout[2] AND $rout[4] AND $rout[5]	 AND (districts.id in ($_REQUEST[districts]))   	              
	    	    GROUP BY d_letter.id
	    	    
	    	    UNION ALL
	    	    
	    	    SELECT	CONCAT('b-',warehouse.id),
                		a_letter.`end_date`, 
                		CONCAT('ბ  – ',a_letter.id)  as `letter`,
                		COUNT(*),
                		CONCAT(`client`.`name`,'(',`client_objects`.`name`, ')') AS `client`,
                		cities.`name`,
                		CONCAT(`client_objects`.address_name , ' ', `address_types`.`name` , ' ', `client_objects`.`address_number` ) AS `address`,
                		districts.`name`
                FROM	warehouse
                JOIN    a_letter ON warehouse.a_letter_id=a_letter.id
                JOIN    warehouse_detail ON warehouse_detail.warehouse_id =warehouse.id AND warehouse_detail.actived=1
                JOIN	client_objects ON `client_objects`.`id` = `a_letter`.`client_object_id`
                JOIN	client	ON `client`.`id` = `client_objects`.`client_id`
                LEFT JOIN	cities ON `cities`.`id` = `client_objects`.`region`
                LEFT JOIN	address_types ON `address_types`.`id` = `client_objects`.`address_type`
                LEFT JOIN	postal_codes	ON `postal_codes`.`id` = `client_objects`.postal_code_id
                LEFT JOIN	districts ON `districts`.`id` = `postal_codes`.`district_id`
                WHERE	a_letter.receiver1=0   AND 
                		a_letter.id>4500      AND
                		a_letter.actived=1    AND						
                		ISNULL(a_letter.b_letter_overhead_id) AND 
	    	             warehouse.`status`>4	 AND
						a_letter.`status` in (3,4) 	AND 
	    	            $rout[1]  AND $rout[3] AND $rout[4] AND $rout[5]  AND (districts.id in ($_REQUEST[districts]))
	    	    GROUP BY a_letter.id 
	    	     
                UNION ALL
	    	    
                SELECT	CONCAT('e-',warehouse.id),
                        d_letter.`end_date`,
                        CONCAT('ე – ',d_letter.id)  as `letter`,
                        COUNT(*),
                        CONCAT(`client`.`name`,'(',`client_objects`.`name`, ')') AS `client`,
                        cities.`name`,
                        CONCAT(`client_objects`.address_name , ' ', `address_types`.`name` , ' ', `client_objects`.`address_number` ) AS `address`,
                        districts.`name`
                 FROM	warehouse
                 JOIN   d_letter ON warehouse.d_letter_id=d_letter.id
                 JOIN   warehouse_detail ON warehouse_detail.warehouse_id =warehouse.id AND warehouse_detail.actived=1
                 JOIN	client_objects ON `client_objects`.`id` = `d_letter`.`client_object_id`
                 JOIN	client	ON `client`.`id` = `client_objects`.`client_id`
                 LEFT JOIN	cities ON `cities`.`id` = `client_objects`.`region`
                 LEFT JOIN	address_types ON `address_types`.`id` = `client_objects`.`address_type`
                 LEFT JOIN	postal_codes	ON `postal_codes`.`id` = `client_objects`.postal_code_id
                 LEFT JOIN	districts ON `districts`.`id` = `postal_codes`.`district_id`
                 WHERE	d_letter.receiver1=0   AND 
                        d_letter.id>450       AND
                        d_letter.actived=1    AND							
                        ISNULL(d_letter.e_letter_overhead_id) AND 
	    	            warehouse.`status`>4	 AND
						d_letter.`status` in (3,4) 	AND
	    	            $rout[1] AND $rout[2] AND $rout[4] AND $rout[5]  AND (districts.id in ($_REQUEST[districts]))
	    	    GROUP BY d_letter.id");
	    	    break;
	    	case 1:
	    		$rResult = mysql_query("--  a  --------------------------------
                SELECT		`a_letter`.`id` AS letter,
        					`a_letter`.`end_date`,
        					CONCAT(CONCAT('ა–',a_letter.id)) as `letter`,
        					COUNT(*),
        					CONCAT(`client`.`name`,'(',`client_objects`.`name`, ')') AS `client`,
        					`cities`.`name`,
        					CONCAT(`client_objects`.address_name , ' ', `address_types`.`name` , ' ', `client_objects`.`address_number` ) AS `address`,
        					`districts`.`name`,
        					persons.`name`,
        					IFNULL(CONCAT('<a href=\'#\'><button class=\'btn1\' onclick=\"FinishOverheadRS(\'a\' ,',	a_letter.overhead_id,')\">ა დასრულება</button></a>'),
        					CONCAT('<a href=\'#\'><button class=\'btn\' 	onclick=\"send_rs(\'a\' ,',		a_letter.id,		 ')\">ა გააქტიურება</button></a>'))	as `button`
                FROM		 `a_letter`
                JOIN   warehouse ON warehouse.a_letter_id=a_letter.id
                JOIN   warehouse_detail ON warehouse_detail.warehouse_id = warehouse.id AND warehouse_detail.actived=1
                LEFT JOIN   rs_wdsl_status ON rs_wdsl_status.id=a_letter.overhead_id
                JOIN	`client_objects` ON `client_objects`.`id` = `a_letter`.`client_object_id`
                JOIN	`client`	ON `client`.`id` = `client_objects`.`client_id`
                LEFT JOIN	`cities` ON `cities`.`id` = `client_objects`.`region`
                LEFT JOIN	`address_types` ON `address_types`.`id` = `client_objects`.`address_type`
                LEFT JOIN	`postal_codes`	ON `postal_codes`.`id` = `client_objects`.postal_code_id
                JOIN	`persons`  ON   `persons`.`id` =  a_letter.receiver
                LEFT JOIN	`districts` ON `districts`.`id` = `postal_codes`.`district_id`
                WHERE  ISNULL(rs_wdsl_status.end_date)
                		AND	(a_letter.receiver !=-1)
                		AND	(a_letter.receiver !=0)
                	    AND a_letter.id>4000	and a_letter.actived=1
                GROUP BY letter
UNION ALL
-- -------------------------------b-------------------------
                SELECT		`a_letter`.`id` AS letter,
        					`a_letter`.`end_date`,
        					CONCAT(CONCAT('ბ–',a_letter.id)) as `letter`,
        					COUNT(*),
        					CONCAT(`client`.`name`,'(',`client_objects`.`name`, ')') AS `client`,
        					`cities`.`name`,
        					CONCAT(`client_objects`.address_name , ' ', `address_types`.`name` , ' ', `client_objects`.`address_number` ) AS `address`,
        					`districts`.`name`,
        					persons.`name`,
        					IFNULL(CONCAT('<a href=\'#\'><button class=\'btn1\' onclick=\"FinishOverheadRS(\'b\' ,',	a_letter.b_letter_overhead_id,')\">ბ დასრულება</button></a>'),
        					CONCAT('<a href=\'#\'><button class=\'btn\' 	onclick=\"send_rs(\'b\' ,',						a_letter.id,				 ')\">ბ გააქტიურება</button></a>'))	as `button`
                FROM		 `a_letter`
                LEFT JOIN   warehouse ON warehouse.a_letter_id=a_letter.id
                LEFT JOIN   warehouse_detail ON warehouse_detail.warehouse_id = warehouse.id AND warehouse_detail.actived=1
                LEFT JOIN  rs_wdsl_status ON rs_wdsl_status.id=a_letter.b_letter_overhead_id
                LEFT JOIN	`client_objects` ON `client_objects`.`id` = `a_letter`.`client_object_id`
                LEFT JOIN	`client`	ON `client`.`id` = `client_objects`.`client_id`
                LEFT JOIN	`cities` ON `cities`.`id` = `client_objects`.`region`
                LEFT JOIN	`address_types` ON `address_types`.`id` = `client_objects`.`address_type`
                LEFT JOIN	`postal_codes`	ON `postal_codes`.`id` = `client_objects`.postal_code_id
                JOIN	`persons`  ON   `persons`.`id` =  a_letter.receiver1
                LEFT JOIN	`districts` ON `districts`.`id` = `postal_codes`.`district_id`
                WHERE  ISNULL(rs_wdsl_status.end_date)
                		AND	(a_letter.receiver1 !=-1)
                		AND	(a_letter.receiver1 !=0)
                	    AND a_letter.id>3800	and a_letter.actived=1
GROUP BY letter
UNION ALL
--   -----------------------------  d  --------------------------------
SELECT		`d_letter`.`id` AS letter,
					`d_letter`.`end_date`,
					CONCAT(CONCAT('დ–',d_letter.id)) as `letter`,
					COUNT(*),
					CONCAT(`client`.`name`,'(',`client_objects`.`name`, ')') AS `client`,
					`cities`.`name`,
					CONCAT(`client_objects`.address_name , ' ', `address_types`.`name` , ' ', `client_objects`.`address_number` ) AS `address`,
					`districts`.`name`,
					persons.`name`,
					IFNULL(CONCAT('<a href=\'#\'><button class=\'btn1\' onclick=\"FinishOverheadRS(\'d\' ,',	d_letter.overhead_id,')\">დ დასრულება</button></a>'),
								 CONCAT('<a href=\'#\'><button class=\'btn\' 	onclick=\"send_rs(\'d\' ,',		d_letter.id,')\">დ გააქტიურება</button></a>'))	as `button`
FROM		 `d_letter`
LEFT JOIN   warehouse ON warehouse.d_letter_id=d_letter.id
LEFT JOIN   warehouse_detail ON warehouse_detail.warehouse_id = warehouse.id AND warehouse_detail.actived=1
LEFT JOIN  rs_wdsl_status ON rs_wdsl_status.id=d_letter.overhead_id
LEFT JOIN	`client_objects` ON `client_objects`.`id` = `d_letter`.`client_object_id`
LEFT JOIN	`client`	ON `client`.`id` = `client_objects`.`client_id`
LEFT JOIN	`cities` ON `cities`.`id` = `client_objects`.`region`
LEFT JOIN	`address_types` ON `address_types`.`id` = `client_objects`.`address_type`
LEFT JOIN	`postal_codes`	ON `postal_codes`.`id` = `client_objects`.postal_code_id
JOIN	`persons`  ON   `persons`.`id` =  d_letter.receiver
LEFT JOIN	`districts` ON `districts`.`id` = `postal_codes`.`district_id`
WHERE  ISNULL(rs_wdsl_status.end_date)
		AND	(d_letter.receiver !=-1)
		AND	(d_letter.receiver !=0)
	     AND d_letter.id>300		and d_letter.actived=1
GROUP BY letter
UNION ALL
-- ---------------------------------------------b
SELECT		`d_letter`.`id` AS letter,
					`d_letter`.`end_date`,
					CONCAT(CONCAT('ე–',d_letter.id)) as `letter`,
					COUNT(*),
					CONCAT(`client`.`name`,'(',`client_objects`.`name`, ')') AS `client`,
					`cities`.`name`,
					CONCAT(`client_objects`.address_name , ' ', `address_types`.`name` , ' ', `client_objects`.`address_number` ) AS `address`,
					`districts`.`name`,
					persons.`name`,
					IFNULL(CONCAT('<a href=\'#\'><button class=\'btn1\' onclick=\"FinishOverheadRS(\'e\' ,',	d_letter.e_letter_overhead_id,')\">ე დასრულება</button></a>'),
								 CONCAT('<a href=\'#\'><button class=\'btn\' 	onclick=\"send_rs(\'e\' ,',		d_letter.id,				 ')\">ე გააქტიურება</button></a>'))	as `button`
FROM		 `d_letter`
LEFT JOIN   warehouse ON warehouse.d_letter_id=d_letter.id
LEFT JOIN   warehouse_detail ON warehouse_detail.warehouse_id = warehouse.id AND warehouse_detail.actived=1
LEFT JOIN  rs_wdsl_status ON rs_wdsl_status.id=d_letter.e_letter_overhead_id
LEFT JOIN	`client_objects` ON `client_objects`.`id` = `d_letter`.`client_object_id`
LEFT JOIN	`client`	ON `client`.`id` = `client_objects`.`client_id`
LEFT JOIN	`cities` ON `cities`.`id` = `client_objects`.`region`
LEFT JOIN	`address_types` ON `address_types`.`id` = `client_objects`.`address_type`
LEFT JOIN	`postal_codes`	ON `postal_codes`.`id` = `client_objects`.postal_code_id
JOIN	`persons`  ON   `persons`.`id` =  d_letter.receiver1
LEFT JOIN	`districts` ON `districts`.`id` = `postal_codes`.`district_id`
WHERE  ISNULL(rs_wdsl_status.end_date)
		AND	(d_letter.receiver1 !=-1)
		AND	(d_letter.receiver1 !=0)
	     AND d_letter.id>300		and d_letter.actived=1
GROUP BY letter

	    	");
	    		break;
	    		case 2:
	    			$rResult = mysql_query("SELECT		   `warehouse`.`id`,
            	    							           rs_wdsl_status.start_date,
            										       IFNULL(`a_letter`.end_date,`d_letter`.`end_date`),
            										       rs_wdsl_status.end_date,
                                    					   IF( TIMEDIFF(IFNULL(`a_letter`.end_date,`d_letter`.`end_date`),rs_wdsl_status.end_date)>0,
                        									TIMEDIFF(IFNULL(`a_letter`.end_date,`d_letter`.`end_date`),rs_wdsl_status.end_date),
                        									CONCAT('<div style=\"background-color: red\">',
                        													TIMEDIFF(IFNULL(`a_letter`.end_date,`d_letter`.`end_date`),rs_wdsl_status.end_date)
                        													, '</div>')) AS სამუშაოს_სხვაობა,

            										       IFNULL( CONCAT('დ	– ',d_letter.id), CONCAT('ა	– ',a_letter.id)) as `letter`,
            										       CONCAT(`client`.`name`,'(',`client_objects`.`name`, ')') AS `client`,
            											   persons.`name`
            								FROM		 `warehouse`
            								LEFT JOIN	`a_letter` ON `a_letter`.`id` = `warehouse`.a_letter_id and a_letter.actived=1
            								LEFT JOIN   warehouse_detail ON warehouse_detail.warehouse_id =warehouse.id
            								LEFT JOIN	`d_letter` ON `d_letter`.`id` = `warehouse`.`d_letter_id` and d_letter.actived=1
            								JOIN   rs_wdsl_status ON rs_wdsl_status.id=COALESCE(d_letter.e_letter_overhead_id,a_letter.b_letter_overhead_id)
            								LEFT JOIN	`client_objects` ON `client_objects`.`id` = `warehouse`.`client_object_id`
            								LEFT JOIN	`client`	ON `client`.`id` = `client_objects`.`client_id`
            								LEFT JOIN	`cities` ON `cities`.`id` = `client_objects`.`region`
            								LEFT JOIN	`address_types` ON `address_types`.`id` = `client_objects`.`address_type`
            								LEFT JOIN	`postal_codes`	ON `postal_codes`.`id` = `client_objects`.postal_code_id
            								LEFT JOIN	`persons`  ON   `persons`.`id` = IFNULL(d_letter.responsible_person, a_letter.responsible_person)
            								LEFT JOIN	`districts` ON `districts`.`id` = `postal_codes`.`district_id`
            								WHERE	(NOT ISNULL( `warehouse`.`a_letter_id` ) OR NOT ISNULL( `warehouse`.`d_letter_id` ))
            											 AND	((a_letter.status >5) OR (d_letter.`status` >5))
            								GROUP BY letter
            							ORDER BY  `warehouse`.`id` DESC");
	    			break;


	    	}

		$data = array(
			"aaData"	=> array()
		);

		while ( $aRow = mysql_fetch_array( $rResult ) )
		{
			$row = array();
			for ( $i = 0 ; $i < $count; $i++ )
			{
				// General output
				$row[] = $aRow[$i];
				if($i == ($count - 1)){
					$row[] = '<input type="checkbox" name="check_' . $aRow[$hidden] . '" class="check" value="' . $aRow[$hidden] . '" />';
				}
			}

			$data['aaData'][] = $row;
		}

        break;
    case 'change_responsible_person':
    	$letters 			= split(',' ,$_REQUEST['lt']);
    	$responsible_person = $_REQUEST['rp'];
    	$car_id 			= $_REQUEST['ci'];
    	//print_r($letters);
    	//return 0;

    	ChangeResponsiblePerson($letters, $responsible_person, $car_id);

    	break;
    default:
       $error = 'Action is Null';
}

$data['error'] = $error;

echo json_encode($data);

function ChangeResponsiblePerson($letters, $responsible_person, $car_id){
    
    
    
	foreach($letters as $letter) {
	    $letter1   = split('-' ,$letter);
		$rResult = mysql_fetch_assoc( mysql_query("	SELECT		warehouse.a_letter_id as `a_letter`,
																warehouse.d_letter_id as `d_letter`
													FROM		warehouse
													WHERE		warehouse.id = '$letter1[1]'"));
		$lt[]=$letter1;
		$c[0]=''; $c[1]='-- ';
		if ($letter1[0]=='e' || $letter1[0]=='b') {
		   $c[0]='-- '; $c[1]='';
		}
		if( $rResult['a_letter'] !='' ){
				mysql_query("	UPDATE	a_letter
								SET		$c[1] a_letter.receiver1	= '$responsible_person',
										$c[0] a_letter.receiver		= '$responsible_person',
				                        a_letter.car_id				= '$car_id'
								WHERE	a_letter.id =$rResult[a_letter]");
		}else if( $rResult['d_letter'] !='' ){
				mysql_query("	UPDATE	d_letter
								SET		$c[1] d_letter.receiver1	= '$responsible_person',
										$c[0] d_letter.receiver		= '$responsible_person',
										d_letter.car_id				= '$car_id'
								WHERE	d_letter.id = $rResult[d_letter]");
		}
	}
	//print_r($lt);
	//echo "sdfsdfsdf";
}

function GetPersons(){
	$data = '';
	$req = mysql_query("SELECT `id`, `name`
						FROM `persons`
						WHERE `persons`.actived != 0");

	$data .= '<option value="' . 0 . '" selected="selected">' . '' . '</option>';

	while( $res = mysql_fetch_assoc($req)){
			$data .= '<option value="' . $res['id'] . '">' . $res['name'] . '</option>';
	}
	return $data;
}

function GetAutoNumber(){
	$data = '';
	$req = mysql_query("SELECT	`id`, `name`
						FROM	`object`
						WHERE	`type` = 3 && `object`.actived != 0");
	$data .= '<option value="' . 0 . '" selected="selected">' . '' . '</option>';

	while( $res = mysql_fetch_assoc($req)){
			$data .= '<option value="' . $res['id'] . '">' . $res['name'] . '</option>';
	}

	return $data;
}

function get_signature(){ 
    $data = '';
    $req =  mysql_query("SELECT client_object_persons.id, 
                                client_object_persons.`name`,
                                a_letter.b_letter_signature as signature
                         FROM  `a_letter`
                         JOIN  client_object_persons ON a_letter.client_object_id=client_object_persons.client_object_id AND client_object_persons.actived=1
                         WHERE a_letter.b_letter_overhead_id=$_REQUEST[id]
                        UNION
                        SELECT client_object_persons.id, 
                        	   client_object_persons.`name`,
                        	   d_letter.e_letter_signature as signature
                        FROM  `d_letter`
                        JOIN  client_object_persons ON d_letter.client_object_id=client_object_persons.client_object_id AND client_object_persons.actived=1
                        WHERE d_letter.e_letter_overhead_id=$_REQUEST[id]
        
        ");
    
    
    $data .= '<option value="' . 0 . '" selected="selected">' . '' . '</option>';
    
    while( $res = mysql_fetch_assoc($req)){
        if ($res['id']==$res['signature']) {
            $data .= '<option value="' . $res['id'] . '" selected="selected">' . $res['name'] . '</option>';
        }else
        $data .= '<option value="' . $res['id'] . '">' . $res['name'] . '</option>';
    }
    
    return $data;
}
function GetPage1(){
    $data = '
		<div id="dialog-form">
			<fieldset>
				<legend>ძირითადი ინფორმაცია</legend>
				<table width="100%" class="dialog-form-table" cellpadding="10px" >
					<tr>
						<th><label for="responsible_person">ხელმომწერი პირი</label></th>						
					</tr>
					<tr>
					<th>
							<select id="signature_person" class="idls address">'. get_signature() .'</select>
					</th>

				</table>
			</fieldset>
		</div>';
    return $data;

}
function GetPage(){
	$data = '
		<div id="dialog-form">
			<fieldset>
				<legend>ძირითადი ინფორმაცია</legend>
				<table width="100%" class="dialog-form-table" cellpadding="10px" >
					<tr>
						<th><label for="responsible_person">პასუხისმგებელი პირი</label></th>
						<th><label for="car_id">ა/მ ნომერი</label></th>
					</tr>
					<tr>
						<th>
							<select id="responsible_person" class="idls address">'. GetPersons() .'</select>
						</th>
						<th>
							<select id="car_id" class="idls user_id">'. GetAutoNumber() .'</select>
						</th>
					</tr>
				</table>
			</fieldset>
		</div>';
	return $data;

}

?>